<template>
  <el-dialog
    title="用户名"
    :visible="show"
    :append-to-body="true"
    width="500px"
    @close="close"
    center>
    <div class="edit-menu-dialog-box">
      <div class="el-input-box">
        <el-input size="medium" v-model="changeValue" placeholder="请输入用户名"/>
      </div>
    </div>
    <span slot="footer" class="add-menu-dialog-footer">
      <el-button type="primary" size="medium" @click="commit">更改</el-button>
    </span>
  </el-dialog>
</template>

<script>
import Api from "@/utils/api.js";

export default {
  /**
   * show，显示
   * name，用户名
   */
  props: ["show", 'userName'],

  data(){
    return{
      changeValue : "",
    }
  },

  watch: {
    userName(newV, oldV) {
      if(newV){
        this.changeValue = newV;
      }
    } 
  },

  methods:{
    close(){
      this.$emit('close')
    },

    commit(){
      // 请求接口
      this.$axios.post(Api.USER_INFO_USER_NAME, {userName : this.changeValue}).then( _ =>{
        this.$emit('changeName', this.changeValue)
        this.close()
         this.$message.success("修改成功！");
      }).catch(res =>{
        this.$message.warning(res.message);
      })
    },
  }
}
</script>

<style lang="less" scoped>
@import '@/assets/css/index.less';

.edit-menu-dialog-box{
  padding-top: 20px;
  padding-bottom: 20px;

  .el-input-box{
    margin-bottom: 10px;
  }
}

// 添加菜单弹框
.add-menu-dialog-footer{
  
  .el-button{
    width: 200px;
  }
}
</style>
